var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0}), (i.foodModel = void 0);
var s = e("AssetsMap"),
    c = e("BundleNames"),
    l = e("GlobalParam"),
    d = e("Util"),
    u = e("ConfigGameData"),
    p = e("GameData"),
    h = e("nodePoolManager"),
    f = e("GameModuleView"),
    _ = (function () {
        function e() {
            (this.image_url = ""), (this.isRecovery = !0);
        }
        return (
            (e.prototype.init = function () {
                var e = "";
                if (this.foodType == p.FoodType.Magnet) e = "prop_magnet";
                else if (this.foodType == p.FoodType.Double) e = "prop_double";
                else if (this.foodType == p.FoodType.FirstFood)
                    (this.foodIndex = d.default.randomFrom(1, 3)), (e = "type1_" + this.foodIndex);
                else if (this.foodType == p.FoodType.SecondFood)
                    (this.foodIndex = d.default.randomFrom(1, 6)), (e = "type2_" + this.foodIndex);
                else if (this.foodType == p.FoodType.ThirdFood)
                    (this.foodIndex = d.default.randomFrom(1, 8)), (e = "type3_" + this.foodIndex);
                else if (this.foodType == p.FoodType.DieFood)
                    2 == (t = d.default.randomFrom(1, 5))
                        ? (e = "type2_5")
                        : 1 == t
                        ? (e = "type2_2")
                        : 3 == t
                        ? (e = "type1_1")
                        : 4 == t
                        ? (e = "type1_2")
                        : 5 == t && (e = "type1_3");
                else if (this.foodType == p.FoodType.StoreFood) {
                    var t;
                    e = "type4_" + (t = d.default.randomFrom(1, 2));
                } else
                    this.foodType == p.FoodType.Shit
                        ? ((e = "shit"), ad.curr_platform == window.ad.Platform.TOU_TIAO && (e = "shit_tt"))
                        : this.foodType == p.FoodType.Missile
                        ? (e = "prop_missile")
                        : this.foodType == p.FoodType.Shield
                        ? (e = "prop_shield")
                        : this.foodType == p.FoodType.Stars && (e = "stars");
                this.image_url = e;
            }),
            (e.prototype.showFood = function () {
                (this.node.x = this.x), (this.node.y = this.y), (this.node.scale = this.scale);
                var e = game.BundleManager.instance
                    .getBundle(c.default.Game)
                    .get(s.default.GameBundle.textures.assetsList[this.image_url], cc.SpriteFrame);
                this.node.getComponent(cc.Sprite).spriteFrame = e;
            }),
            e
        );
    })();
i.foodModel = _;
var y = function () {
        this.nodeList = [];
    },
    m = cc._decorator,
    g = m.ccclass,
    v =
        (m.property,
        (function (e) {
            function t() {
                var t = (null !== e && e.apply(this, arguments)) || this;
                return (
                    (t.map_size = 0),
                    (t.blockMap = []),
                    (t.addFoodList = []),
                    (t.addFoodScaleList = []),
                    (t.block_width = 0),
                    (t.block_height = 0),
                    (t.block_width_num = 50),
                    (t.block_height_num = 50),
                    (t.showFoodList = []),
                    (t.magnetList = []),
                    (t.doubleList = []),
                    (t.shieldList = []),
                    (t.missileList = []),
                    (t.starsList = []),
                    (t.init_food = []),
                    (t.portal = null),
                    t
                );
            }
            return (
                a(t, e),
                (t.prototype.start = function () {
                    this.initBaseInfo();
                    for (var e = [], t = 0; t < l.default.GameConfigData.FirstFood; t++) e.push(p.FoodType.FirstFood);
                    for (t = 0; t < l.default.GameConfigData.SecondFood; t++) e.push(p.FoodType.SecondFood);
                    for (t = 0; t < l.default.GameConfigData.ThirdFood; t++) e.push(p.FoodType.ThirdFood);
                    for (var o = 0; o < l.default.GameConfigData.Magnet; o++) e.push(p.FoodType.Magnet);
                    for (o = 0; o < l.default.GameConfigData.Double; o++) e.push(p.FoodType.Double);
                    if (f.default.Insance.gameModel == p.GameModel.eatChicken) {
                        for (o = 0; o < l.default.GameConfigData.shield; o++) e.push(p.FoodType.Shield);
                        for (o = 0; o < l.default.GameConfigData.stars; o++) e.push(p.FoodType.Stars);
                    }
                    this.TimingAddFood(e);
                }),
                (t.prototype.initBaseInfo = function () {
                    this.map_size = p.default.instance.MapSize;
                    for (var e = 0; e < this.block_width_num; e++) {
                        this.blockMap[e] = [];
                        for (var t = 0; t < this.block_height_num; t++) {
                            var o = new y();
                            (o.x = e), (o.y = t), (o.nodeList = []), this.blockMap[e].push(o);
                        }
                    }
                    (this.block_width = this.map_size / this.block_width_num),
                        (this.block_height = this.map_size / this.block_height_num);
                }),
                (t.prototype.updateF = function () {
                    if (
                        p.default.instance.gameState == p.GameState.play ||
                        p.default.instance.gameState == p.GameState.ready
                    ) {
                        if ((this.renderRecycling2(), this.init_food.length > 0)) {
                            var e = this.init_food.shift();
                            this.addFood(e, null, null);
                        }
                        if (0 != this.addFoodList.length)
                            for (var t = 0; t < this.addFoodList.length; t++) {
                                var o = this.addFoodList[t],
                                    n = 3;
                                o.length < 3 && (n = o.length);
                                for (var i = 0; i < n; i++)
                                    (e = o[i]),
                                        this.addFood(
                                            p.FoodType.DieFood,
                                            cc.v2(e.x, e.y),
                                            Math.floor(10 * this.addFoodScaleList[t]),
                                            this.addFoodScaleList[t]
                                        );
                                o.splice(0, n),
                                    0 == o.length &&
                                        (this.addFoodList.splice(t, 1), this.addFoodScaleList.splice(t, 1));
                            }
                    }
                }),
                (t.prototype.renderRecycling = function () {
                    var e,
                        t,
                        o,
                        n,
                        i = h.default.instance.gameModelInstance._gameCameraPos,
                        a = p.default.instance.size;
                    (e = i.x - a.width / 2),
                        (t = i.x + a.width / 2),
                        (o = i.y - a.height / 2),
                        (n = i.y + a.height / 2);
                    for (
                        var r = this.getBlockIDByPos(e, o), s = this.getBlockIDByPos(t, n), c = [], l = r.x;
                        l <= s.x;
                        l++
                    )
                        for (var d = r.y; d <= s.y; d++) {
                            var u = {x: l, y: d};
                            c.push(u);
                        }
                    var f = new Date().getTime(),
                        _ = [],
                        y = 0;
                    for (l = 0; l < this.showFoodList.length; l++) {
                        var m = !0;
                        for (d = 0; d < c.length; d++)
                            this.showFoodList[l].x == c[d].x && this.showFoodList[l].y == c[d].y && (m = !1);
                        if (m)
                            for (
                                var g = this.blockMap[this.showFoodList[l].x][this.showFoodList[l].y].nodeList, v = 0;
                                v < g.length;
                                v++
                            )
                                (C = g[v]).node && (_.push(C.node), (C.node = null));
                    }
                    var w = new Date().getTime();
                    w - f > 5 && console.log(" 回收 执行时间是：", w - f);
                    var b = new Date().getTime();
                    for (l = 0; l < c.length; l++) {
                        for (m = !0, d = 0; d < this.showFoodList.length; d++)
                            c[l].x == this.showFoodList[d].x && c[l].y == this.showFoodList[d].y && (m = !1);
                        if (m)
                            for (g = this.blockMap[c[l].x][c[l].y].nodeList, v = 0; v < g.length; v++) {
                                var C;
                                (C = g[v]).node ||
                                    (y >= _.length
                                        ? ((C.node = h.default.instance.getFoodNode()), (C.node.parent = this.node))
                                        : ((C.node = _[y]), y++),
                                    C.showFood());
                            }
                    }
                    var k = new Date().getTime();
                    k - b > 5 && console.log(" 显示 执行时间是：", k - b);
                    var N = new Date().getTime();
                    for (v = y; v < _.length; v++) {
                        var B = _[v];
                        h.default.instance.delFoodNode(B);
                    }
                    var P = new Date().getTime();
                    P - N > 5 && console.log(" 对象池 执行时间是：", P - N), (this.showFoodList = c);
                }),
                (t.prototype.renderRecycling2 = function () {
                    for (var e = 0; e < this.blockMap.length; e++)
                        for (var t = this.blockMap[e], o = 0; o < t.length; o++)
                            for (var n = t[o].nodeList, i = 0; i < n.length; i++) {
                                var a = n[i],
                                    r = h.default.instance.gameModelInstance._gameCameraPos,
                                    s = p.default.instance.size;
                                if (
                                    a.x >= r.x - s.width / 2 &&
                                    a.x <= r.x + s.width / 2 &&
                                    a.y >= r.y - s.height / 2 &&
                                    a.y <= r.y + s.height / 2
                                ) {
                                    if (a.node) continue;
                                    (a.node = h.default.instance.getFoodNode()),
                                        (a.node.parent = this.node),
                                        a.showFood();
                                } else {
                                    if (!a.node) continue;
                                    (a.node.parent = null), h.default.instance.delFoodNode(a.node), (a.node = null);
                                }
                            }
                }),
                (t.prototype.TimingAddFood = function (e) {
                    var t = this;
                    if (0 != e.length) {
                        var o = e.shift();
                        this.addFood(o),
                            this.scheduleOnce(function () {
                                t.TimingAddFood(e);
                            }, 0);
                    }
                }),
                (t.prototype.addFood = function (e, t, o, n) {
                    if ((void 0 === t && (t = null), void 0 === o && (o = null), void 0 === n && (n = 1), !t)) {
                        var i = this.map_size / 2 - 100;
                        (e != p.FoodType.Magnet && e != p.FoodType.Double) || (i -= 500);
                        var a = d.default.randomFrom(0, i),
                            r = d.default.randomFrom(0, 360),
                            s = a * Math.sin((3.14 * r) / 180),
                            c = a * Math.cos((3.14 * r) / 180);
                        (s = Math.floor(s)), (c = Math.floor(c)), (t = cc.v2(s, c));
                    }
                    o || (o = u.default.GetFoodScoreByType(e)), e == p.FoodType.StoreFood && (n = 3);
                    var l = t.sub(cc.Vec2.ZERO).mag();
                    if (l > this.map_size / 2 - 100) {
                        var h = ((this.map_size / 2 - 100) / l) * 100,
                            f = d.default.randomFrom(-h, h) / 100;
                        (t.x = t.x * f), (t.y = t.y * f);
                    }
                    var y = new _();
                    (y.foodType = e), (y.score = o), (y.scale = n), (y.x = t.x), (y.y = t.y), y.init();
                    var m = this.getBlockIDByPos(t.x, t.y);
                    this.blockMap[m.x][m.y].nodeList.push(y),
                        e == p.FoodType.Magnet && this.magnetList.push(y),
                        e == p.FoodType.Double && this.doubleList.push(y),
                        e == p.FoodType.Missile && this.missileList.push(y),
                        e == p.FoodType.Shield && this.shieldList.push(y),
                        e == p.FoodType.Stars && this.starsList.push(y),
                        e == p.FoodType.DieFood || e == p.FoodType.Shit ? (y.isRecovery = !1) : (y.isRecovery = !0);
                }),
                (t.prototype.addShitFood = function (e) {
                    this.addFood(p.FoodType.Shit, e);
                }),
                (t.prototype.SnakeDieAddFood = function (e, t) {
                    this.addFoodList.push(e), this.addFoodScaleList.push(t);
                }),
                (t.prototype.isEatFood = function (e, t) {
                    for (var o = this.getBlockIDByPos(e.x, e.y), n = [], i = o.x - 1; i <= o.x + 1; i++)
                        if (!(i < 0 || i > this.block_width_num - 1))
                            for (var a = o.y - 1; a <= o.y + 1; a++)
                                if (!(a < 0 || a > this.block_height_num - 1))
                                    for (var r = this.blockMap[i][a].nodeList, s = 0, c = r.length; s < c; s++) {
                                        var l = c - s - 1,
                                            d = r[l];
                                        if (e.sub(cc.v3(d.x, d.y)).mag() < t) {
                                            var u = r.splice(l, 1);
                                            n.push(u[0]),
                                                d.foodType == p.FoodType.Magnet && this.delMagnetList(d),
                                                d.foodType == p.FoodType.Double && this.delDoubleList(d),
                                                d.foodType == p.FoodType.Missile && this.delMissileList(d),
                                                d.foodType == p.FoodType.Shield && this.delShieldList(d),
                                                d.foodType == p.FoodType.Stars && this.delStarsList(d);
                                        }
                                    }
                    return n;
                }),
                (t.prototype.getMapData = function (e) {
                    for (
                        var t = this.getBlockIDByPos(e.x, e.y),
                            o = this.blockMap[t.x][t.y].nodeList,
                            n = 0,
                            i = o.length;
                        n < i;
                        n++
                    )
                        if (!(c = o[i - n - 1]).isRecovery)
                            return ((l = {}).x = c.x), (l.y = c.y), (l.length = o.length), l;
                    for (var a = t.x - 1; a <= t.x + 1; a++)
                        if (!(a < 0 || a > this.block_width_num - 1))
                            for (var r = t.y - 1; r <= t.y + 1; r++)
                                if (!(r < 0 || r > this.block_height_num - 1 || (a == t.x && r == t.y))) {
                                    var s = this.blockMap[a][r].nodeList;
                                    for (n = 0, i = s.length; n < i; n++) {
                                        var c, l;
                                        if (!(c = s[i - n - 1]).isRecovery)
                                            return ((l = {}).x = c.x), (l.y = c.y), (l.length = s.length), l;
                                    }
                                }
                    return null;
                }),
                (t.prototype.delMissileList = function (e) {
                    for (var t = 0, o = this.missileList.length; t < o; t++)
                        this.missileList[t] == e && this.missileList.splice(t, 1);
                }),
                (t.prototype.delShieldList = function (e) {
                    for (var t = 0, o = this.shieldList.length; t < o; t++)
                        this.shieldList[t] == e && this.shieldList.splice(t, 1);
                }),
                (t.prototype.delMagnetList = function (e) {
                    for (var t = 0, o = this.magnetList.length; t < o; t++)
                        this.magnetList[t] == e && this.magnetList.splice(t, 1);
                }),
                (t.prototype.delDoubleList = function (e) {
                    for (var t = 0, o = this.doubleList.length; t < o; t++)
                        this.doubleList[t] == e && this.doubleList.splice(t, 1);
                }),
                (t.prototype.delStarsList = function (e) {
                    for (var t = 0, o = this.starsList.length; t < o; t++)
                        this.starsList[t] == e && this.starsList.splice(t, 1);
                }),
                (t.prototype.getBlockPosByID = function (e, t) {
                    return (
                        (e = e * this.block_width - this.map_size / 2),
                        (t = t * this.block_height - this.map_size / 2),
                        cc.v2(e, t)
                    );
                }),
                (t.prototype.getBlockIDByPos = function (e, t) {
                    return (
                        (e += this.map_size / 2),
                        (t += this.map_size / 2),
                        (e = Math.floor(e / this.block_width)),
                        (t = Math.floor(t / this.block_height)),
                        e < 0 && (e = 0),
                        e > this.block_width_num - 1 && (e = this.block_width_num - 1),
                        t < 0 && (t = 0),
                        t > this.block_height_num - 1 && (t = this.block_height_num - 1),
                        cc.v2(e, t)
                    );
                }),
                (t.prototype.showPortal = function () {
                    p.default.instance.isStoreHose ||
                        ((this.portal = game.UIManager.instance.createNodeByPreloading(
                            c.default.Game,
                            s.default.GameBundle.prefabs.assetsList.portal
                        )),
                        (this.portal.parent = this.node),
                        this.portal.setPosition(
                            cc.v3(d.default.randomFrom(-2e3, 2e3), d.default.randomFrom(-2e3, 2e3), 0)
                        ),
                        (f.default.Insance.viewModel.tip_arrow.active = !0));
                }),
                (t.prototype.hidePortal = function () {
                    this.portal.destroy(), (this.portal = null), (f.default.Insance.viewModel.tip_arrow.active = !1);
                }),
                r([g], t)
            );
        })(cc.Component));
i.default = v;
